﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace CommonUtils
{
    public static class ButtonUtil
    {
        public static void Disable(params Button[] buttons)
        {
            foreach (var button in buttons)
                button.Disable();
        }

        public static void Enable(params Button[] buttons)
        {
            foreach (var button in buttons)
                button.Enable();
        }

        /// <summary>
        /// 获取文件路径
        /// </summary>
        public static void SelectFileWhenClick(this Button button, TextBox textBox, bool save = true, params string[] namesOrExtentions)
        => button.Click += delegate { textBox.SelectFile(save, namesOrExtentions); };

        public static void TriggerClick(this Button button)
        => button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));

        public static void InvokeClick(this Button button)
        => button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));

        public static void OpenFolderOnClick(this Button button, TextBox textBox)
        {
            //这里不能继承 Open(this Button button, string path)
            //因为string是值类型，textbox是引用，肯定要打开引用值
            button.Click += delegate { FolderUtil.Open(textBox.Text); };
        }

        public static void ClickToCopyText(this Button button, TextBox textBox)
        {
            button.Click += delegate
            {
                //textBox.Clip();
                //SystemUtil.SetClipboard(textBox.Text);
                //Clipboard.SetText(textBox.Text);
                System.Windows.Forms.Clipboard.SetText(textBox.Text);
            };
        }
    }
}
